<template>

    <Form ref="formValidate" :model="formValidate" :label-width="80" style="position: relative;"> 
        <Row class="grkzxx-list">
            <Col span="8">
                <Row>
                <Col span="12" class="grkzxx-title">
                    <div>是否独生子女</div> 
                </Col>
                <Col span="12" class="grkzxx-con">
                    <div>
                        <RadioGroup v-model="formValidate.is_onlychild">
                            <Radio label="1">是</Radio>
                            <Radio label="0">否</Radio>
                        </RadioGroup>
                    </div>
                </Col>
                </Row>
            </Col>
            <Col span="8">
                <Row>
                <Col span="12" class="grkzxx-title">
                    <div>是否受过学前教育</div> 
                </Col>
                <Col span="12" class="grkzxx-con">
                    <div>
                        <RadioGroup v-model="formValidate.is_pre_school_education">
                            <Radio label="1">是</Radio>
                            <Radio label="0">否</Radio>
                        </RadioGroup>
                    </div>
                </Col>
                </Row>
            </Col>
            <Col span="8">
                <Row>
                <Col span="12" class="grkzxx-title">
                    <div>残疾人类型</div> 
                </Col>
                <Col span="12">
                    <div>                                    
                        <Select v-model="formValidate.disabled_status_id" style="width:100%" transfer clearable>
                            <Option  v-for="item in listDictionary.disabled_status" :value="item.dictionary_id" :key="item.dictionary_id">{{item.dictionary_name.zh?item.dictionary_name.zh:item.dictionary_name.mn}}</Option>            
                        </Select>
                    </div>
                </Col>
                </Row>
            </Col>
        </Row>

        <Row class="grkzxx-list">
            <Col span="8">
                <Row>
                <Col span="12" class="grkzxx-title">
                    <div>是否孤儿</div> 
                </Col>
                <Col span="12" class="grkzxx-con">
                    <div>
                        <RadioGroup v-model="formValidate.is_orphan">
                            <Radio label="1">是</Radio>
                            <Radio label="0">否</Radio>
                        </RadioGroup>
                    </div>
                </Col>
                </Row>
            </Col>
            <Col span="8">
                <Row>
                <Col span="12" class="grkzxx-title">
                    <div>是否烈士或优抚子女</div> 
                </Col>
                <Col span="12" class="grkzxx-con">
                    <div>
                        <RadioGroup v-model="formValidate.is_martyr">
                            <Radio label="1">是</Radio>
                            <Radio label="0">否</Radio>
                        </RadioGroup>
                    </div>
                </Col>
                </Row>
            </Col>
            <Col span="8">
                <Row>
                <Col span="12" class="grkzxx-title">
                    <div>随班就读</div> 
                </Col>
                <Col span="12" class="grkzxx-con">
                    <div>
                        <RadioGroup v-model="formValidate.is_study_in_class">
                            <Radio label="1">是</Radio>
                            <Radio label="0">否</Radio>
                        </RadioGroup>
                    </div>
                </Col>
                </Row>
            </Col>
        </Row>

        <Row class="grkzxx-list">
            <Col span="8">
                <Row>
                <Col span="12" class="grkzxx-title">
                    <div>是否由政府购买学位</div> 
                </Col>
                <Col span="12" class="grkzxx-con">
                    <div>
                        <RadioGroup v-model="formValidate.is_government_degree">
                            <Radio label="1">是</Radio>
                            <Radio label="0">否</Radio>
                        </RadioGroup>
                    </div>
                </Col>
                </Row>
            </Col>
            <Col span="8">
                <Row>
                <Col span="12" class="grkzxx-title">
                    <div>是否需要申请过资助</div> 
                </Col>
                <Col span="12" class="grkzxx-con">
                    <div>
                        <RadioGroup v-model="formValidate.is_funding">
                            <Radio label="1">是</Radio>
                            <Radio label="0">否</Radio>
                        </RadioGroup>
                    </div>
                </Col>
                </Row>
            </Col>
            <Col span="8">
                <Row>
                <Col span="12" class="grkzxx-title">
                    <div>是否享受一补</div> 
                </Col>
                <Col span="12" class="grkzxx-con">
                    <div>
                        <RadioGroup v-model="formValidate.is_supplement">
                            <Radio label="1">是</Radio>
                            <Radio label="0">否</Radio>
                        </RadioGroup>
                    </div>
                </Col>
                </Row>
            </Col>
        </Row>
            
        <Row class="grkzxx-list">
            <Col span="8">
                <Row>
                <Col span="12" class="grkzxx-title">
                    <div>是否留守儿童</div> 
                </Col>
                <Col span="12" class="grkzxx-con">
                    <div>
                        <RadioGroup v-model="formValidate.is_left_behind_children">
                            <Radio label="1">是</Radio>
                            <Radio label="0">否</Radio>
                        </RadioGroup>
                    </div>
                </Col>
                </Row>
            </Col>
            <Col span="8">
                <Row>
                <Col span="12" class="grkzxx-title">
                    <div>是否迁随子女</div> 
                </Col>
                <Col span="12" class="grkzxx-con">
                    <div>
                        <RadioGroup v-model="formValidate.is_move_with">
                            <Radio label="1">是</Radio>
                            <Radio label="0">否</Radio>
                        </RadioGroup>
                    </div>
                </Col>
                </Row>
            </Col>
        </Row>
        <FormItem style="width:90%;">
            <Button type="primary" @click="handleSubmit('formValidate')">保存</Button>
        </FormItem>  
        <div style="clear:both"></div>
        <Spin size="large" fix v-if="spinShow"></Spin>                     
    </Form> 
</template>
<script>
export default {
    props: {
        infoOld: {
            type: [Boolean,Number,Object,Array],
            default: false
        },
        typeother: {
            type: [Boolean,String],
            default: false
        }
    },
    data() {
        return {
            infoUrl:`api/student/v1/studentexpansion/lists/${this.infoOld.expansion?this.infoOld.expansion.student_expansion_id : ''}`,//请求单条数据
            saveUrl:'',//保存接口
            saveType:null,//保存方式
            
            // 数据字典获取数据  血型
            listDictionary:{
                disabled_status:[]
            },
            spinShow:false,
         
            
            infoOldObj:null,// 个人辅助数据

            // 个人辅助信息
            formValidate: {
                is_onlychild: '0',//是否独生子女
                is_pre_school_education:'0',//是否经过学前教育
                is_left_behind_children:'0',//是否留守儿童   
                is_orphan:'0',//是否孤儿   
                is_martyr:'0',//是否是烈士或优抚子女   
                is_study_in_class:'0',//是否随班就读   
                disabled_status_id:null,//残疾人类型   
                is_government_degree:'0',//是否由政府购买学位   
                is_funding:'0',//是否需要申请过资助   
                is_supplement:'0',//是否享受一补   
                is_move_with:'0',//是否迁随子女        
                user_id:this.infoOld.user_id,          
            },
        }
    },
    methods: {
        
        /************************************************************
         * 
         * 单条获取个人辅助信息
         * 
         ************************************************************/
        infoData(){
            this.spinShow=true
            this.$http.get(this.infoUrl).then(val=>{ 
                this.infoOldObj = JSON.parse(JSON.stringify(val.data))

                this.formValidate.is_onlychild = this.infoOldObj.is_onlychild.toString()// 是否独生子女
                this.formValidate.is_pre_school_education = this.infoOldObj.is_pre_school_education.toString()// 是否经过学前教育
                this.formValidate.is_left_behind_children = this.infoOldObj.is_left_behind_children.toString()// 是否留守儿童
                this.formValidate.is_orphan = this.infoOldObj.is_orphan.toString()// 是否孤儿
                this.formValidate.is_martyr = this.infoOldObj.is_martyr.toString()// 是否是烈士或优抚子女
                this.formValidate.is_study_in_class = this.infoOldObj.is_study_in_class.toString()// 是否随班就读
                this.formValidate.is_government_degree = this.infoOldObj.is_government_degree.toString()// 是否由政府购买学位
                this.formValidate.is_funding = this.infoOldObj.is_funding.toString()// 是否需要申请过资助
                this.formValidate.is_supplement = this.infoOldObj.is_supplement.toString()// 是否享受一补
                this.formValidate.is_move_with = this.infoOldObj.is_move_with.toString()// 是否迁随子女
                this.formValidate.disabled_status_id = parseInt(this.infoOldObj.disabled_status_id)// 残疾人类型

                this.spinShow=false
            }).catch(err=>{
                console.log(err);
                if(err.code && err.code==422) {
                    this.$Message.error(err.message);
                }
                this.spinShow=false
            })
        },
        
        /************************************************************
         * 
         * 个人辅助信息提交
         * 
         ************************************************************/
        handleSubmit () {   
            this.spinShow=true    
            this.saveType(this.saveUrl,this.formValidate)
            .then(val=>{
                this.$Message.success(val.message);
                this.$emit('expandback',true)
                this.spinShow=false
            }) 
            .catch(err=>{
                console.log(err);
                if(err.code && err.code==422) {
                    this.$Message.error(err.message);
                }
                this.spinShow=false
            })   
        },

        /************************************************************
         * 
         * 数据字典获取数据
         * 
         ************************************************************/
        listDictionaryFun(){
            this.spinShow=true
            this.$http.get('api/dictionary/v1/dictionary/pidquerys?disabled_status')
            .then((response) => {
                this.listDictionary=response.data
                this.spinShow=false
            })
            .catch(err=>{
                console.log(err);
                if(err.code && err.code==422) {
                    this.$Message.error(err.message);
                }
                this.spinShow=false
            })
        },


    },
    created() {
        this.listDictionaryFun()
        
        if(this.infoOld.expansion){
            // 如果有值 就是修改
            this.infoData()
            this.saveUrl=`api/student/v1/studentexpansion/update/${this.infoOld.expansion.student_expansion_id}`
            this.saveType=this.$http.put
        }else{
            // 如果没有有值 就是添加  
            this.saveUrl='api/student/v1/studentexpansion/create'
            this.saveType=this.$http.post
        }
        
    },    
    watch:{
        infoOld: {
            handler (val) {
                if(this.infoOld.expansion){
                    // 如果有值 就是修改
                    // this.infoUrl=`api/student/v1/studentexpansion/lists/${this.infoOld.expansion?this.infoOld.expansion.student_expansion_id : ''}`,//请求单条数据
                    // this.infoData()
                    this.saveUrl=`api/student/v1/studentexpansion/update/${this.infoOld.expansion.student_expansion_id}`
                    this.saveType=this.$http.put
                }else{
                    // 如果没有有值 就是添加  
                    this.saveUrl='api/student/v1/studentexpansion/create'
                    this.saveType=this.$http.post
                }
            }
        },
    },

}

</script>
<style lang="less">
.grkzxx-list{
    margin-top: 24px;
    .grkzxx-title{
        text-align:right;
        padding:5px 10px;
    }
    .grkzxx-con{
        padding:5px 10px;
        border:1px solid #ccc;
        border-radius:5px;
    }
    .grkzxx-con:hover{
        cursor: pointer;
        border:1px solid #007d7f;
    }
}
</style>